package net.zjitc.servlet;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

/**
 * Created by Administrator on 2017/9/27.
 */
@WebServlet(name = "RequestServlet",urlPatterns = "/RequestServlet")
public class RequestServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("test/html;charset=utf-8");
        //请求头里面的东西
        //User-Agent
        String value=request.getHeader("User-Agent");
        PrintWriter out=response.getWriter();
        out.write(value);
        out.write("<br/>---------------<br/>");

        //获取所有头的信息输出到页面？？
        //Enumeration getHeaderNames():获取所有请求头名称
        Enumeration enumeration=request.getHeaderNames();
        while (enumeration.hasMoreElements()){
            //获得到名字
            String name=(String) enumeration.nextElement();
            //通过名字获得内容
            String values=request.getHeader(name);
            out.write(name+":"+value+"<br/>");
        }
    }
}
